module.exports = {
	selectImageData: selectImageData,
	upLoadFileData: upLoadFileData
}

function selectImageData(that, url, filePath, scccess) {
	return selectImage(that, url, filePath, scccess)
}

function upLoadFileData(that, url, pathUrl, filePath, scccess) {
	return upLoadFile(that, url, pathUrl, filePath, scccess)
}

function selectImage(that, url, filePath, scccess) {
	var newHeader = {
		'Authorization': uni.getStorageSync('TOKEN_EN')
	}
	newHeader['Terminal'] = 'WECHAT_APP';
	uni.chooseImage({
		count: 1,
		sizeType: ['original', 'compressed'],
		sourceType: ['album'],
		success(res) {
			console.log('tempFilePaths', res);
			uni.uploadFile({
				url: url,
				filePath: res.tempFilePaths[0],
				name: 'file',
				header: newHeader,
				formData: {
					'filePath': filePath,
				},
				success(res) {
					var resData = JSON.parse(res.data);
					if (resData.code == 200) {
						return scccess(resData);
					} else {
						uni.showToast({
							title: resData.msg,
							icon: 'none',
							duration: 2000,
						});
					}
				}
			})
		}
	})
}

function upLoadFile(that, url, pathUrl, filePath, scccess) {
	var newHeader = {
		'Authorization': uni.getStorageSync('TOKEN_EN')
	}
	console.log('22222222222',url);
	console.log('22222222222',pathUrl);
	console.log('22222222222',filePath);	
	newHeader['Terminal'] = 'WECHAT_APP';
	uni.uploadFile({
		url: url,
		filePath: filePath,
		name: 'file',
		header: newHeader,
		formData: {
			'filePath': pathUrl,
		},
		success(res) {
			console.log('eeeeeeeeeeeee', res);
			var resData = JSON.parse(res.data);
			if (resData.code == 200) {
				return scccess(resData);
			} else {
				uni.showToast({
					title: resData.msg,
					icon: 'none',
					duration: 2000,
				});
			}
		}
	})
}